import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../util/request-util";
import {FormUtil} from "../../../util/form-util";
import {API} from "../../../constants/constants";
import {Observable} from "rxjs";
import {MsgResult} from "../../../models/msg-result";
import {Monitor} from "./monitor";

@Injectable()
export class MonitorService {

  constructor(
    private request:RequestUtil,
    private formUtil : FormUtil
  ) { }

  //添加站点设备
  siteMonitorAdd(monitor : Monitor):Observable<MsgResult>{
    let params = this.formUtil.serialize(monitor);
    return this.request.post(API.siteMonitorAdd,params);
  }

  //删除站点设备
  siteMonitorDelete(id : string):Observable<MsgResult>{
    return this.request.delete(API.siteMonitorDelete+"/"+id+"?format=json");
  }

  //批量删除站点设备
  siteMonitorDeletes(ids : Array<string>):Observable<MsgResult>{
    let params="ids="+ids;
    return this.request.post(API.siteMonitorDeletes,params);
  }

  getSiteMonitorById(id : string):Observable<MsgResult>{
    return this.request.get(API.getSiteMonitorById+"/"+id+"?format=json");
  }

  //修改站点设备
  siteMonitorEdit(monitor : Monitor):Observable<MsgResult>{
    let params = this.formUtil.serialize(monitor);
    return this.request.put(API.siteMonitorEdit+"/"+monitor.id+"?format=json&"+params);
  }

  //修改站点设备
  assignSite(params,id):Observable<MsgResult>{
    return this.request.put(API.siteMonitorEdit+"/"+id+"?format=json&"+params);
  }

  /**
   * 获取设备类型
   * @returns {Observable<MsgResult>|any}
   */
  getMonitor():Observable<MsgResult>{
    return this.request.get(API.getMonitor);
  }

  /**
   * 保存或修改 为设备分配的权重
   * @param param 参数
   * @param snCode 设备编号
   * @returns {Observable<MsgResult>|any}
   */
  siteMonitorSetAddOrEdit(param ,snCode :string):Observable<MsgResult>{
    let params=param+"&snCode="+snCode;
    return this.request.post(API.siteMonitorSetAddOrEdit,params);
  }

  /**
   * 删除某设备权重
   * @param id 主键
   * @returns {Observable<MsgResult>|any}
   */
  siteMonitorSetDelete(id :string):Observable<MsgResult>{
    return this.request.delete(API.siteMonitorSetDelete+"/"+id+"?format=json");
  }

}
